function acceptIdea(idea_id,email,idea_title){
    var $modal = $('#ajax-modal');
    $.ajax({
        beforeSend:function(){
            //$('#loading_'+key).show();
            $modal.modal('hide');
            $('body').modalmanager('loading');
        },
        url: '/backyard/acceptIdea',
        type:"POST",
        dataType:"json",
        data:{
            idea_id: idea_id,
            email: email,
            idea_title: idea_title,
            post_tags: $('#user_post_tags').val()
        },
        success: function(data)
        {   
            alert(data.msg);
            location.reload(); 
        }
    });
}

function show_accept_form(idea_id,email,idea_title){
    var $modal = $('#ajax-modal');
    $.ajax({
        beforeSend:function(){
            $('body').modalmanager('loading');
        },
        url: '/backyard/show_accept_form',
        type:"POST",
        dataType:"json",
        data:{
            idea_id:idea_id
        },
        success: function(data)
        { 
            $modal.html(data.html);
            $("#user_post_tags").select2({
                tags: ['裝潢好點子','改造前改造後','跟著好俬迷這樣做']
            });        

            $modal.modal('show');
      }
  });
}

function show_reject_form(idea_id){
    var $modal = $('#ajax-modal');
    $.ajax({
        beforeSend:function(){
            $('body').modalmanager('loading');
        },
        url: '/backyard/show_reject_form',
        type:"POST",
        dataType:"json",
        data:{
            idea_id:idea_id
        },
        success: function(data)
        { 
          $modal.html(data.html);
          $modal.modal('show');
      }
  });
}

function rejectIdea(idea_id,email,idea_title){
    if($('#reject_reason').val() != ''){
        var $modal = $('#ajax-modal');
        $.ajax({
            beforeSend:function(){
                $('body').modalmanager('loading');
            },
            url: '/backyard/rejectIdea',
            type:"POST",
            dataType:"json",
            data:{
                idea_id: idea_id,
                email: email,
                idea_title: idea_title,
                reject_title: $('#reject_title').val(),
                reject_reason: $('#reject_reason').val()
            },
            success: function(data)
            {   
                $modal.html('');
                $modal.modal('hide');
                alert(data.msg);
                location.reload(); 
            }
        });
    }
    else{
        alert('do not leave the field empty !');
    }
}
